package com.example.beautymakeup.utils;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.util.Map;

public class HttpUtils {

    public static JSONObject post(String content, String url) {
        HttpResponse response = HttpRequest.post(url).header("Content-Type", "application/json")
                .body(content).execute();
        String body = response.body();
        JSONObject jsonObject = JSON.parseObject(body);
        return jsonObject.getJSONObject("data");
    }
    public static JSONObject postAppData(String content, String url) {
        HttpResponse response = HttpRequest.post(url).header("Content-Type", "application/json")
                .body(content).execute();
        String body = response.body();
        JSONObject jsonObject = JSON.parseObject(body);
        return jsonObject.getJSONObject("appdata");
    }
    public static JSONObject get(Map<String, Object> params, String url) {
        String response = HttpUtil.get(url, params);
        JSONObject result = (JSONObject) JSONObject.parse(response);
        return result;
    }
}
